package com.chanyachting.emall.action.hr;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.form.OfferSearchForm;
import com.chanyachting.emall.service.RecruitmentinformationService;
import com.chanyachting.emall.serviceImpl.RecruitmentinformationServiceImpl;
import com.chanyachting.emall.util.PageUtil;

public class QueryOfferJob  extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//一般页面记录数
		int COMMON_PAGE_SIZE = 20;
		
		OfferSearchForm tForm = (OfferSearchForm)form;
		int currentPage = tForm.getCurrentPage();
		int pageSize = COMMON_PAGE_SIZE;
		
		RecruitmentinformationService reService = new RecruitmentinformationServiceImpl();
		List alList = null;
		
		
		int recordCnt = reService.getRecruitmentInfCount();
		
		int pageCount = recordCnt%pageSize == 0?recordCnt/pageSize:(recordCnt/pageSize + 1);
		
		if (currentPage < 1) {
			currentPage = 1;
		} else if (currentPage > pageCount) {
			currentPage = 1;
		}
		alList = reService.getRecruitmentInfByPage(currentPage,pageSize);
		tForm.setCompanyInfor(alList);
		String toPageAct = PageUtil.getGotoAction(request.getRequestURL().toString(), request.getParameterMap());
		String linkStr = PageUtil.getFy3(pageCount, currentPage, toPageAct);
		tForm.setLinkStr(linkStr);
		return mapping.findForward("offerJobs");
	}
}
